#include "stdafx.h"
#include "../sgp/MouseRegion.h"

namespace ja2{ namespace sgp
{
	MouseRegion::MouseRegion(Priority Priority_, std::uint_least32_t Flags, std::int_least16_t LeftX, std::int_least16_t LeftY, std::int_least16_t RightX, std::int_least16_t RightY, Point const &MousePos, Point const &MousePosRel, std::uint_least16_t ButtonState, std::uint_least16_t FastHelptimer, std::string const &FastHelpText)
		: m_PriorityLevel(Priority_),
		m_Flags(Flags),
		m_TopLeftX(LeftX),
		m_TopLeftY(LeftY),
		m_BottomRightX(RightX),
		m_BottomRightY(RightY),
		m_MousePosition(MousePos),
		m_MousePositionRelative(MousePosRel),
		m_ButtonState(ButtonState),
		m_FastHelpTimer(FastHelptimer),
		m_FastHelpText(FastHelpText)
	{
	}

	MouseRegion::Priority MouseRegion::priority() const
	{
		return m_PriorityLevel;
	}

	void MouseRegion::move_signal(CallbackSignal_t::slot_type const &Signal)
	{
		m_MovementCallback.connect(Signal);
	}

	void MouseRegion::button_signal(CallbackSignal_t::slot_type const &Signal)
	{
		m_ButtonCallback.connect(Signal);
	}

	bool MouseRegion::is_flag_set(Flag Flag_) const
	{
		return (m_Flags & Flag_) != 0;
	}

	void MouseRegion::unset_flag(Flag Flag_)
	{
		m_Flags &= ~Flag_;
	}

	void MouseRegion::set_flag(Flag Flag_)
	{
		m_Flags |= Flag_;
	}

	bool MouseRegion::is_inside(std::int_least16_t TopLeftX, std::int_least16_t TopLeftY, std::int_least16_t BottomRightX, std::int_least16_t BottomRightY) const
	{
		return ((m_TopLeftX <= TopLeftX) && (m_TopLeftY <= TopLeftY) && (m_BottomRightX >= BottomRightX) && (m_BottomRightY >= BottomRightY));
	}

	std::string const &MouseRegion::fast_help_text() const
	{
		return m_FastHelpText;
	}

	void MouseRegion::fast_help_timer(std::uint_least16_t Value)
	{
		m_FastHelpTimer = Value;
	}

	void MouseRegion::movement_callback(std::uint_least32_t Reason) const
	{
		m_MovementCallback(*this, Reason);
	}

	bool MouseRegion::is_cursor_set() const
	{
		return m_Cursor;
	}

	void MouseRegion::set_cursor(CursorType Cursor)
	{
		*m_Cursor = Cursor;
	}

	CursorType MouseRegion::cursor() const
	{
		return *m_Cursor;
	}

	void MouseRegion::set_mouse_position(Point const &Position)
	{
		m_MousePosition = Position;
		m_MousePositionRelative = Point(m_MousePosition.x - m_TopLeftX, m_MousePosition.y - m_TopLeftY);
	}

	void MouseRegion::set_button_state(ButtonState State)
	{
		m_ButtonState |= State;
	}

	void MouseRegion::set_button_state_all(std::uint_least16_t State)
	{
		m_ButtonState = State;
	}

	void MouseRegion::button_callback(std::uint_least32_t Reason)
	{
		m_ButtonCallback(*this, Reason);
	}
}/*sgp*/} /*ja2*/